package cn.com.idmy.cloud.controller;


import cn.com.idmy.cloud.util.LealoneUtil;
import cn.com.idmy.cloud.util.WebUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.SneakyThrows;
import org.dromara.hutool.core.io.file.FileUtil;
import org.jetbrains.annotations.NotNull;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;

public class BaseBackupController {
    @SneakyThrows
    @PostMapping("/export")
    void excel(@NotNull HttpServletResponse response) {
        var pair = LealoneUtil.runBackup();
        byte[] bytes = FileUtil.readBytes(pair.getRight());
        WebUtil.write(response, MediaType.APPLICATION_OCTET_STREAM, pair.getLeft(), bytes);
    }
}
